using System;
using System.Web;
using Dimebrain.TweetSharp.Fluent;

namespace KickStart.Data
{
    public static class UserExtensions
    {
        public static bool IsFollowingTweetastica(this User user)
        {
            var areFriends = FluentTwitter.CreateRequest()
                .Configuration.UseGzipCompression()
                .AuthenticateWith(user.Token, user.TokenSecret)
                .Friendships()
                .Verify(user.UserId)
                .IsFriendsWith("tweetastica")
                .AsJson();

            var response = areFriends.Request();
            return response == "true";
        }

        public static bool IsMe(this User user)
        {
            if (HttpContext.Current.User == null ||
                HttpContext.Current.User.Identity == null ||
                string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
                return false;

            return user.UserId == Convert.ToInt64(HttpContext.Current.User.Identity.Name);
        }
    }
}